package com.weighttracker.android;

import java.text.NumberFormat;

import com.bappi.custom.activities.CustomActivity;
import com.bappi.utils.Utils;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Tab3Activity25 extends CustomActivity{
	
	private EditText weightField,heightField,resultFiled;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		try {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.layout_tab_3_screen_25);
			weightField = (EditText)findViewById(R.id.weight_field);
			heightField = (EditText)findViewById(R.id.height_field);
			resultFiled = (EditText)findViewById(R.id.result_field);
			findViewById(R.id.button_back).setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					finish();
				}
			});
			findViewById(R.id.button_clear).setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					weightField.setText("");
					heightField.setText("");
					resultFiled.setText("");
				}
			});
			findViewById(R.id.button_calculate).setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					double weight  = 0.0;
					int height = 0;
					String text;
					try {
						text = weightField.getText().toString();
						if(text.length()>0){
							weight = Double.parseDouble(text);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					try {
						text = heightField.getText().toString();
						if(text.length()>0){
							height = Integer.parseInt(text);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					
					if(weight<=0 || height<=0){
						Utils.showAlertMessage(getParent(), getString(R.string.message_fill_all_required_fiels));
					}else{
						double value =  (10000*weight)/Math.pow(height, 2);
						NumberFormat nf = NumberFormat.getInstance();
						nf.setMaximumFractionDigits(2);
						nf.setMinimumFractionDigits(2);
						resultFiled.setText(nf.format(value));

					}
//					try {
//						text = fiberField.getText().toString();
//						if(text.length()>0){
//							fiber = Float.parseFloat(text);
//						}
//						if(fiber>0){
//							fiber = 4;
//						}
//					} catch (Exception e) {
//						e.printStackTrace();
//					}
//					double value =  (calories / 50.0) + (fat / 12.0) - (fiber / 5.0);
//					resultFiled.setText(Long.toString((long)Math.ceil(value)));
				}
			});
			
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
}
